package com.lxr0860.lxr0860production_test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lxr0860.lxr0860production_test.adapter.StrengthListAdapter;
import com.lxr0860.lxr0860production_test.bean.FactoryTestItem;
import com.lxr0860.lxr0860production_test.itemactivity.ICC_0860Activity;
import com.lxr0860.lxr0860production_test.itemactivity.USBActivity;
import com.lxr0860.lxr0860production_test.utils.Contants;

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by uniriho on 2018/10/23.
 */

public class StrengthActivity extends Activity {
    private List<FactoryTestItem> items;
    private StrengthListAdapter mAdapter;
    private ListView mLvList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_strength);
        initView();
        initData();
        initEvent();
    }

    private void initView(){
        mLvList= (ListView) findViewById(R.id.lv_strength_list);
    }

    private void initData(){
        items=new ArrayList<FactoryTestItem>();
        items.add(new FactoryTestItem(Contants.getStrengthType(Contants.STRENGTH_USB),
                true, R.drawable.item_usb, Contants.STRENGTH_USB));
        items.add(new FactoryTestItem(Contants.getStrengthType(Contants.STRENGTH_IC),
                true, R.drawable.item_ic, Contants.STRENGTH_IC));
        items.add(new FactoryTestItem(Contants.getStrengthType(Contants.STRENGTH_KEY),
                true, R.drawable.item_key, Contants.STRENGTH_KEY));
        items.add(new FactoryTestItem(Contants.getStrengthType(Contants.STRENGTH_RECORD),
                true, R.drawable.item_main, Contants.STRENGTH_RECORD));
        mAdapter=new StrengthListAdapter(this,items);
        mLvList.setAdapter(mAdapter);
    }

    private void initEvent(){
        mLvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=null;
                switch (items.get(position).getTestId()) {
                    case Contants.STRENGTH_KEY:
                        break;
                    case Contants.STRENGTH_IC:
                        intent = new Intent(StrengthActivity.this, ICC_0860Activity.class);
                        break;
                    case Contants.STRENGTH_USB:
                        intent = new Intent(StrengthActivity.this, USBActivity.class);
                        break;
                    case Contants.STRENGTH_RECORD:
                        intent =new Intent(StrengthActivity.this, TestRecordActivity.class);
                        break;
                }
                intent.putExtra("testType", Contants.TEST_QIANGHUA);
                startActivity(intent);
            }
        });
    }

}
